#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <assert.h>
#include <math.h>

#include "dominion.h"
#include "dominion_helpers.h"
#include "rngs.h"

int cards_not_equal(int deck1[][500], int deck2[][500], int deck1_count, int deck2_count, int player)
{
	int i;

	if (deck1_count != deck2_count) {
		return 0;
	}

	for (i = 0; i < deck1_count; i++) {
		if (deck1[player][i] != deck2[player][i]) {
			return 0;
		}
	}

	return 1;
}

void test_shuffle()
{
	int player = 0;
	int deck_count = 500;
	struct gameState state;
	int temp_deck[1][500];
	int success;
	int i;

	state.deckCount[player] = deck_count;

	for (i = 0; i < 500; i++) {
		temp_deck[player][i] = (int)floor(Random() * deck_count);
	}

	/* Test One: Random Cards */
	for (i = 0; i < 500; i++) {
		state.deck[player][i] = temp_deck[player][i];
	}

	if (shuffle(player, &state) != -1) {
		success = cards_not_equal(state.deck, temp_deck, state.deckCount[player], deck_count, player);
		if (success) {
			printf("Test One: PASS\n");
		} else {
			printf("Test One: FAIL - Cards are equal\n");
		}
	} else {
		printf("Test One: FAIL - Shuffle failed\n");
	}

	/* Test Two: Player deckCount < 1 */
	state.deckCount[player] = 0;

	if (shuffle(player, &state) == -1) {
		printf("Test Two: PASS\n");
	} else {
		printf("Test Two: FAIL - player deckCount check failed\n");
	}
}

int main(void)
{
	test_shuffle();
	return EXIT_SUCCESS;
}